# backups template script.  Korn shell/UNIX script.
# This script must be altered to use point to your files and instance.
#
# Sample Hot Backup Script for a Unix File System database
# 
# This script is for an Oracle7 database.  For Oracle Version 6, remove
# the "lmode=Y" clauses.  Everything else stays the same.
#
# Set up environment variables:
ORACLE_SID=cc1; export ORACLE_SID
ORACLE_HOME=/orasw/v716; export ORACLE_HOME
#
#  	Step 1.  Perform a tablespace-by-tablespace backup
#	of the datafiles.  Set each tablespace, one at a time,
#	into BEGIN BACKUP state.  Then backup its datafiles
#	and return the tablespace to its normal state.
#
# Note for Unix:  Set up an indicator for SQLDBA (called EOFarch1 here)
#	so that the command file will stay within SQLDBA.
#
sqldba lmode=y <<EOFarch1
connect internal
REM
REM  	Backup the SYSTEM tablespace
REM
alter tablespace SYSTEM begin backup;
!tar -cvf /dev/rmt/0hc /db01/oracle/CC1/sys01.dbf
alter tablespace SYSTEM end backup;
REM  
REM  The SYSTEM tablespace has now been written to a 
REM	tar saveset on the tape device /dev/rmt/0hc.  The 
REM	rest of the tar's must use the "-rvf" clause to append
REM	to that saveset.
REM
REM	Backup the RBS tablespace
REM
alter tablespace RBS begin backup;
!tar -rvf /dev/rmt/0hc /db02/oracle/CC1/rbs01.dbf
alter tablespace RBS end backup;
REM
REM	Backup up the DATA tablespace
REM	For the purposes of this example, this tablespace
REM	will be comprised of two files, data01.dbf and data02.dbf.
REM	The * wildcard will be used in the file name.
REM
alter tablespace DATA begin backup;
!tar -rvf /dev/rmt/0hc /db03/oracle/CC1/data0*.dbf
alter tablespace DATA end backup;
REM
REM	Backup the INDEXES tablespace
REM
alter tablespace INDEXES begin backup;
!tar -rvf /dev/rmt/0hc /db04/oracle/CC1/indexes01.dbf
alter tablespace INDEXES end backup;
REM
REM	Backup the TEMP tablespace	
REM
alter tablespace TEMP begin backup;
!tar -rvf /dev/rmt/0hc /db05/oracle/CC1/temp01.dbf
alter tablespace TEMP end backup;
REM
REM  	Follow the same pattern to backup the rest
REM	of the tablespaces.
REM
REM
REM		Step 2.  Backup the archived redo log files.
REM
REM	First, stop the archiving process.  This will keep
REM	additional archived redo log files from being written
REM	to the destination directory during this process.
REM
archive log stop
REM
REM	Exit SQLDBA, using the indicator set earlier.
exit
EOFarch1
#
# 	Record which files are in the destination directory.
#  	Do this by setting an environment variable that is
#	equal to the directory listing for the destination directory.
#	For this example, the log_archive_dest is 
#	/db01/oracle/arch/CC1.
#
FILES=`ls /db01/oracle/arch/CC1/arch*.dbf`; export FILES
#
#	Now go back into SQLDBA and restart the 
#	archiving process.  Set an indicator (called EOFarch2 
#	in this example).
#
sqldba lmode=y <<EOFarch2
connect internal
archive log start;
exit
EOFarch2
#
#  Now back up the archived redo logs to the tape
#	device via the "tar" command, then delete them
# 	from the destination device via the "rm" command.
#
tar -rvf /dev/rmt/0hc $FILES
rm -f $FILES
#
#		Step 3.  Backup the control file to a disk file.
#
sqldba lmode=y <<EOFarch3
alter database backup controlfile to
	'db01/oracle/CC1/CC1controlfile.backup';
exit
EOFarch3
#
# 	Backup the control file to the tape.
#
tar -rvf /dev/rmt/0hc /db01/oracle/CC1/CC1controlfile.backup
#
#	End of hot backup script.


